package com.zhufeng.gateway.db.route;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @ClassName: GatewayBeanFactoryPostProcessor
 * @Description TODO
 * @author 月夜烛峰
 * @date 2022/9/16 14:29
 */
//@Component
public class GatewayBeanFactoryPostProcessor implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        // do nothing
    }

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        registry.removeBeanDefinition("readBodyRoutePredicateFactory");
        BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(CustomReadBodyRoutePredicateFactory.class).setScope(BeanDefinition.SCOPE_SINGLETON).setRole(BeanDefinition.ROLE_SUPPORT).getBeanDefinition();
        registry.registerBeanDefinition("readBodyRoutePredicateFactory", beanDefinition);
    }

}

